package com.notary.tx_live_plugin.platform;

import androidx.annotation.NonNull;

import com.notary.tx_live_plugin.util.TxConstant;
import com.notary.tx_live_plugin.util.PlayManager;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

/**
 * 直播实现 在线播放，接收flutter消息处理MethodCallHandler
 */
public class PlayMethodCallHandlerImpl implements MethodChannel.MethodCallHandler {

    private final PlayManager playManager;
    public PlayMethodCallHandlerImpl(PlayManager playManager){
        this.playManager = playManager;
    }

    @Override
    public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
        switch (call.method){
            case TxConstant.PlayMethod.startPlay: //开启直播适配播放
                playManager.startPlay(call.arguments);
                break;
            case TxConstant.PlayMethod.stopPlay: //结束播放
                playManager.stopPlay();
                break;
            case TxConstant.PlayMethod.onPause:
                playManager.onPause();
                break;
            case TxConstant.PlayMethod.onResume:
                playManager.onResume();
                break;
            case TxConstant.PlayMethod.onDestroy:
                playManager.onDestroy();
                break;
            case TxConstant.PlayMethod.firstPlayRtmp:
                playManager.firstPlayRtmp();
                break;
            case TxConstant.PlayMethod.seek:
                //修改播放进度
                playManager.seek(call.arguments);
                break;
            case TxConstant.PlayMethod.isPlaying: //是否正在播放
                result.success(playManager.isPlaying());
                return;
            default:
                result.notImplemented();
                return;
        }
        result.success(true);
    }
}
